<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/7/8
 * Time: 11:05
 */

namespace app\admin\helper;


class SearchHelper
{

    static public function getStatusList(){
        $list = [
            0=>'__all__',
            1=>'__on__',
            2=>'__off__',
        ];
        return LangHelper::convertLang($list,'field');
    }

    /**
     * 返回当月区间数据
     * @return string
     */
    static public function getMonthDateRange(){
        return date("2018-01-01", time())." - ".date("Y-m-d", time());
    }

    /**
     * 返回当天区间段
     * @return string
     */
    static public function getDateRange(){
        return date("Y-m-d")." - ".date("Y-m-d", time());
    }

    /**
     * 返回单天时间
     * @return false|string
     */
    static public function getNowDate(){
        return date("Y-m-d", time());
    }


    static public function convertValue(&$search){
        //填充value
        foreach ($search as $k=>$v) {
            //存在需要动态生成的表单value
            if (isset($v['value']) && $k!='button' && strpos($v['value'],'function:') !== false ){
                $function_name = explode('function:',$v['value'])[1];
                if(strpos($function_name,'(') !== false){
                    $params = explode(',',explode(')',explode('(',$function_name)[1])[0]);
                    $value = call_user_func_array('\app\admin\helper\SearchHelper::'.explode('(',$function_name)[0],$params);
                }else{
                    $value = call_user_func_array('\app\admin\helper\SearchHelper::'.$function_name,[0]);
                }
                $search[$k]['value'] = $value;
            }
        }
    }

}